import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutterapp/model/login_page_model.dart';

class Login extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;
    final loginPageModel = Provider.of<LoginPageModel>(context)..setContext(context);
    return Scaffold(
      appBar: AppBar(
        title: Text('Login'),
      ),
      body: Container(
        margin: EdgeInsets.only(left: 20, right: 20),
        child: SingleChildScrollView(
          padding: const EdgeInsets.symmetric(horizontal: 16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              SizedBox(height: 48.0),
              Text(
                'Login Travelalls',
                style: TextStyle(fontSize: 24.0, fontStyle: FontStyle.italic),
              ),
              SizedBox(height: 48.0),
              Form(
                child: TextFormField(
                  controller: loginPageModel.emailController,
                  decoration: InputDecoration(
                      filled: true,
                      prefixIcon: Icon(Icons.email),
                      fillColor: Colors.transparent,
                      border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(30),
                          borderSide: BorderSide()),
                      hintText: 'E-mail'),
                  style: TextStyle(textBaseline: TextBaseline.alphabetic),
                  keyboardType: TextInputType.emailAddress,
                ),
              ),
              SizedBox(height: 48.0),
              Form(
                child: ConstrainedBox(
                  constraints: BoxConstraints(maxWidth: size.width),
                  child: TextFormField(
                    controller: loginPageModel.passwordController,
                    obscureText: true,
                    decoration: InputDecoration(
                        contentPadding: const EdgeInsets.symmetric(vertical: 20.0),
                        filled: true,
                        prefixIcon: Icon(Icons.lock),
                        fillColor: Colors.transparent,
                        border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(30),
                            borderSide: BorderSide()),
                        hintText: 'Password'),
                    style: TextStyle(textBaseline: TextBaseline.alphabetic),
                    keyboardType: TextInputType.emailAddress,
                  ),
                ),
              ),
              SizedBox(height: 48.0),
              Container(
                height: 60,
                width: size.width - 80,
                child: FlatButton(
                  color: Color.fromARGB(255, 58, 125, 148),
                  child: Text(
                    'Login',
                    style: TextStyle(
                      fontSize: 20,
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(40.0)),
                  onPressed: loginPageModel.logic.onLogin,
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
